﻿
<div ms-controller="tmpmodelview">
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            分类
        </label>
        <div class="controls">
            <select class="input-large input-xfat" ms-duplex="ModelData.Type1">
                <option ms-repeat-el="TypeList1" ms-attr-value="el.ID">{{el.TypeName}}</option>
            </select>
            <select class="input-large input-xfat" ms-duplex="ModelData.Type2">
                <option ms-repeat-el="TypeList2" ms-attr-value="el.ID">{{el.TypeName}}</option>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            标题：
        </label>
        <div class="controls">
            <input type="text" class="input-xlarge input-xfat" placeholder="请输入标题" ms-duplex="ModelData.Title" >
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            描述：
        </label>
        <div class="controls">
            <input type="text" class="input-xlarge input-xfat" placeholder="请输入标题" ms-duplex="ModelData.Desp" >
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            照片：
        </label>
        <div class="controls" style="width:900px">
            <ul class="sui-row-fluid" id="layer-photos-demo">
                <li class="span2" ms-repeat-el="FileData">
                    <div class="img-round">
                        <img ms-attr-layer-src="{{ComFunJS.FilePath(el)}}" ms-attr-data-id="el" ms-attr-src="ComFunJS.FilePath(el,'/100/100')" alt="">
                    </div>
                    <label>
                        <label> <a href="javascript:void(0);" class="sui-btn btn-bordered btn-small btn-danger" ms-click="DelFile(el)">删除</a> </label>
                    </label>
                </li>
                <li class="span2">
                    <button ms-click="FileUpload()" style="margin:15px 0" class="sui-btn btn-xlarge btn-success">添加图片</button>
                </li>
            </ul>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            销售价(元)：
        </label>
        <div class="controls">
            <input type="text" class="input-xlarge input-xfat" ms-duplex="ModelData.Price1">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            成本价(元)：
        </label>
        <div class="controls">
            <input type="text" class="input-xlarge input-xfat" ms-duplex="ModelData.Price2">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            可用存款(元)：
        </label>
        <div class="controls">
            <input type="text" class="input-xlarge input-xfat" ms-duplex="ModelData.Point">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            返存款(元)：
        </label>
        <div class="controls">
            <input type="text" class="input-xlarge input-xfat" ms-duplex="ModelData.RePoint">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            配送说明：
        </label>
        <div class="controls">
            <input type="text" class="input-xlarge input-xfat" ms-duplex="ModelData.SendInfo">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            详情：
        </label>
        <div class="controls">
            <textarea id="txtDetails" class="input-xxlarge bw_ueditor" rows="5" ms-duplex="ModelData.Details"></textarea>
        </div>
    </div>

    
</div>

<script type="text/javascript">
    var tempmodel = avalon.define({
        $id: "tmpmodelview",
        ModelData: { "Client": "0", "ID": 0, "Type1": "", "Type2": "", "Title": "", "Desp": "", "ImgUrl": "", "Price1": "", "Price2": "", "Point": "0", "RePoint": "0", "SendInfo": "", "Details": "" },
        TypeList1: [],
        TypeList2: [],
        Init: function (ID) {
            $.getJSON("/adapi/base/cate/list/1/0", function (r) {
                tempmodel.TypeList1 = r.result;
            })

            if (ID) {
                $.getJSON("/adapi/product/model/" + ID, function (r) {
                    if (r.error == "") {
                        tempmodel.ModelData = r.result;
                        if (r.result.ImgUrl) {
                            pmodel.FileData = r.result.ImgUrl.split(",");
                        }
                        setTimeout("ComFunJS.initForm()", 500);
                    }

                })
            } else {
                ComFunJS.initForm();
            }
        },
        tmpSaveData: function () {
            
            tempmodel.ModelData.ImgUrl = pmodel.GetFileIds();

            $.post("/adapi/product/add", tempmodel.ModelData.$model, function (r) {
                if (r.error == "") {
                    top.ComFunJS.winShowMsg("操作成功");
                    top.ComFunJS.close();
                } else {
                    top.ComFunJS.winShowAlert(r.error);
                }

            })
        }

    })
    tempmodel.$watch("ModelData.Type1", function () {
        tempmodel.TypeList2.clear();
        if (tempmodel.ModelData.Type1) {
            $.getJSON("/adapi/base/cate/list/1/" + tempmodel.ModelData.Type1, function (r) {
                tempmodel.TypeList2 = r.result;
            })
        }

    })

</script>
